package com.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.serviceimpl.AnswerServiceImpl;
import com.exam.util.ApiResultHandler;
import com.exam.vo.AnswerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags = "题库模块")
public class AnswerController {

    @Autowired
    private AnswerServiceImpl answerService;
    @ApiOperation(value = "分页查询所有题目")
    @GetMapping("/answers/{page}/{size}")
    public ApiResult findAllQuestion(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
       Page<AnswerVO> answerVOPage = new Page<>(page,size);
       IPage<AnswerVO> answerVOIPage = answerService.findAll(answerVOPage);
       return ApiResultHandler.buildApiResult(200,"查询所有题库",answerVOIPage);
    }
    //根据id和题目类型删除题目
    @ApiOperation(value = "根据id和题目类型删除题目")
    @DeleteMapping("/answers/{questionId}/{type}")
    public ApiResult deleteQuestion(@PathVariable("questionId") Integer questionId, @PathVariable("type") String type){
        boolean b = answerService.deleteByIdAndType(questionId,type);
        if(b){
            return ApiResultHandler.buildApiResult(200,"删除成功",null);
        }
        return ApiResultHandler.buildApiResult(400,"删除失败",null);
    }

}
